Rust Note
Meow King January 06, 2024 Updated: January 06, 2024 #rust #note #collection-
function accept parameters similar type, like
str
,&str
,String
fn accept_all_strings(value: impl AsRef<str>)
just need a string referencefn accept_all_strings(value: impl Into<String>)
need an owned string
-
use
cloned
method to solve some conversion error in iteration collection.
let results = ;
let result: = results.iter.cloned.collect;
- build a map using
fold
andentry
let map: = new;
self.rounds
.iter
.fold
.values
.product
-
Rust built-in traits: see Effective Rust - std-traits.
Additional Note: -
FromStr
trait: str'sparse
method. -
Ownership
-
into_iter
anditer
into_iter
takes ownership, whilteiter
not. So when origin is something likeVec<String>
, theninto_iter
->String
(Item type), whileiter
->&String
; When&Vec<String>
, theninto_iter
->&String
, whileiter
->&&String
-
Useful functions:
-
HashSet
:retain